-- paquetage de base
with Interfaces.C; use Interfaces.C;
with Ada.Text_IO, Ada.Integer_Text_IO;use Ada.Text_IO,Ada.Integer_Text_IO;
with GLib;
-- paquetages de gestion des exceptions
with Ada.Exceptions;use Ada.Exceptions;

-- paquetages de l'interface Homme Machine (gtk)
with Gtk.Window, Gtk.Button, Gtk.Container, Gtk.Table, Gtk.Text_View, Gtk.Label, Gtk.Widget,Gtk.Handlers, Gtk.Marshallers, Gtk.Spin_Button, Gtk.Scrolled_Window, Gtk.Image;


package Lib is

-------------------------------------------------------------------------------------------------------------------------------------------
--								TYPES UTILISéS
-------------------------------------------------------------------------------------------------------------------------------------------

	type Standard;
	type ptr_Standard is access Standard;
	type Central;
	type ptr_Central is access Central;
	type Telephone;
	type ptr_Telephone is access Telephone;
	type Fixe;
	type ptr_Fixe is access Fixe;
	type pages_jaunes is array (1..100) of ptr_Telephone;

-------------------------------------------------------------------------------------------------------------------------------------------
--								TACHE FIXE
-------------------------------------------------------------------------------------------------------------------------------------------


	-- Declaration du type Fixe qui gere une tache telephone fixe
	task type Fixe is
	-- Initialisation du telephone
		entry INIT(unNum : GLib.Guint; tel : ptr_Telephone; s : ptr_Standard);
	-- Initialiser la conversation
		entry DECROCHER;
	-- Mettre fin a la conversation
		entry RACCROCHER(destinataire : in GLib.Guint);
	-- Notifier au Standard que l'on veut appeller un numéros
		entry APPELER(destinataire : in GLib.Guint);
	end Fixe;

-------------------------------------------------------------------------------------------------------------------------------------------
--								TELEPHONE
-------------------------------------------------------------------------------------------------------------------------------------------



	type Telephone is record
	-- fenetre d'interaction
		telephone	: Gtk.Window.Gtk_Window;
		b_appeler	: Gtk.Button.Gtk_Button;
		b_parler	: Gtk.Button.Gtk_Button;
		t_fond		: Gtk.Table.Gtk_Table;
		ecran		: Gtk.Spin_Button.Gtk_Spin_Button;
		msg_entrant	: Gtk.Text_View.Gtk_Text_View;
		msg_sortant	: Gtk.Text_View.Gtk_Text_View;
		fixe		: ptr_Fixe;
		enLigne		: boolean := false;
		img_enLigne	: Gtk.Image.Gtk_Image;
		appel_entrant	: boolean := false;
		monNumero	: integer;
		correspondant	: ptr_Telephone;
		std		: ptr_Standard;
		
	end record;


	package Telephone_Callback is new Gtk.Handlers.User_Callback
			(Gtk.Widget.Gtk_Widget_Record, ptr_Telephone);

	procedure Telephone_New(tel: ptr_Telephone;unNum : GLib.Guint; std : in ptr_Standard);

	procedure Afficher(tel: ptr_Telephone; msg : in String);

	procedure Mettre_en_relation(tel: ptr_Telephone; correspondant : ptr_Telephone);

	procedure Couper_Communication(tel: ptr_Telephone; correspondant : ptr_Telephone);

	procedure Signaler_Appel(tel : ptr_Telephone);

	procedure Action_Appeler 
		(Button: access Gtk.Widget.Gtk_Widget_Record'Class;
		tel : ptr_Telephone);

	procedure Action_Parler 
		(Button: access Gtk.Widget.Gtk_Widget_Record'Class;
		tel : ptr_Telephone);



-------------------------------------------------------------------------------------------------------------------------------------------
--								TACHE STANDARD
-------------------------------------------------------------------------------------------------------------------------------------------

	task type Standard is
		entry INIT(std : ptr_Standard; p : Integer; c : ptr_Central);
		entry CONNECTER(exp : GLib.Guint; dest : GLib.Guint );
		entry DECONNECTER(exp : GLib.Guint; dest : GLib.Guint );
	end Standard;

	-- New_Standard en ada: appel a init annuaire
	procedure Standard_New(std :in out ptr_Standard; c : ptr_Central);

	function getTelephone(ann: in pages_jaunes;num : in integer) return ptr_Telephone;

	procedure initAnnuaire;
	pragma import(c,initAnnuaire,"initAnnuaire");
	function Standard_Init return Integer;
	pragma import(c,Standard_Init,"STANDARD");
	function estDansAnnuaire(dest : Integer; exp : Integer) return integer;
	pragma import(c,estDansAnnuaire,"CONNEXION");
	function getNbTel return Integer;
	pragma import(c,getNbTel,"getNbTel");
	function getNumero(indice_tel : Integer) return Integer;
	pragma import(c,getNumero,"getNumero");

-------------------------------------------------------------------------------------------------------------------------------------------
--								TACHE CENTRAL
-------------------------------------------------------------------------------------------------------------------------------------------


	task type Central is
		entry CONNECTER( exp: ptr_Telephone; dest: ptr_Telephone );
		entry DECONNECTER( exp: ptr_Telephone; dest: ptr_Telephone );
	end Central;


end Lib;
